import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:zootix/screens/mine/zt_mine.controller.dart';
import 'package:zootix/services/zt_translate.service.dart';
import 'package:zootix/store/zt_auth.store.dart';
import 'package:zootix/util/zt_screen_adaper_util.dart';
import 'package:zootix/zt_app_theme.dart';

class ZtMineSettingsPage extends StatelessWidget {
  final _controller = Get.find<ZtMineController>();
  ZtMineSettingsPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: ZtScreenAdaper.width(15)),
      child: ListView.separated(
          separatorBuilder: (_, index) => const Divider(
                color: Color(0xFFCCCCCC),
              ),
          itemBuilder: ((_, index) => _buildSettingsItem(
                index,
              )),
          itemCount: 4),
    );
  }

  Widget _buildSettingsItem(int index) {
    switch (index) {
      // auto translate
      case 0:
        return Container(
            padding: EdgeInsets.symmetric(vertical: ZtScreenAdaper.width(10)),
            child: Row(
              children: [
                Text(
                  'Auto Translate',
                  style: TextStyle(fontSize: ZtScreenAdaper.sp(18)),
                ),
                const Spacer(),
                Obx(() => CupertinoSwitch(
                    activeColor: ZtAppTheme.primaryColor,
                    value: ZtTranslateService.to.autoTranslate.value,
                    onChanged: (value) async {
                      ZtTranslateService.to.autoTranslate.value = value;
                    })),
              ],
            ));
      case 1:
        return InkWell(
            onTap: () async {
              await ZtAuthStore.to.deleteAccount();
            },
            child: Container(
                padding:
                    EdgeInsets.symmetric(vertical: ZtScreenAdaper.width(10)),
                child: Row(
                  children: [
                    Text(
                      'Delete acount',
                      style: TextStyle(fontSize: ZtScreenAdaper.sp(18)),
                    ),
                  ],
                )));
      case 2:
        return InkWell(
            onTap: () async {
              await ZtAuthStore.to.logout(force: true);
            },
            child: Container(
                padding:
                    EdgeInsets.symmetric(vertical: ZtScreenAdaper.width(10)),
                child: Row(
                  children: [
                    Text(
                      'Logout',
                      style: TextStyle(fontSize: ZtScreenAdaper.sp(18)),
                    ),
                  ],
                )));
      default:
        return SizedBox();
    }
  }
}
